package cn.waxcc.mapper;

import cn.waxcc.pojo.Commodity;
import cn.waxcc.utils.RedisUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
import static cn.waxcc.utils.RedisConstant.OVERALL_SHOPPING_COMMODITY;
import static cn.waxcc.utils.RedisConstant.SHOPPING_COMMODITY;


public class CommodityMapper {

    private static  HashMap<String, Commodity> map;

    private RedisUtil redisUtil;

    public CommodityMapper(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
        redisUtil.setCacheMap(OVERALL_SHOPPING_COMMODITY,map);
    }

    static {
       map = new HashMap<>();
        Commodity commodity1 = new Commodity("1", "苹果14", "5200", 1, false);
        Commodity commodity2 = new Commodity("2", "暗夜精灵9", "8400", 1, true);
        Commodity commodity3 = new Commodity("3", "华为手机", "6000", 1, true);

        map.put(SHOPPING_COMMODITY+commodity1.getId(),commodity1);
        map.put(SHOPPING_COMMODITY+commodity2.getId(),commodity2);
        map.put(SHOPPING_COMMODITY+commodity3.getId(),commodity3);
    }

}
